package com.yc.baseapi;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.mysql.cj.util.StringUtils;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeTest {

	/**
	 * 一样
	 */
	public void m1() {
		Long t1 = (new Date()).getTime();
		Long t2 = System.currentTimeMillis();
		System.out.println("t1=" + t1);
		System.out.println("t2=" + t2);
	}
	
	public void m2() {
		String str = "19690827";
		StringBuffer sb = new StringBuffer(str);
		sb.insert(4, "-");
		sb.insert(7, "-");
		sb.append(" 00:00:00");
		System.out.println(sb.toString());
		System.out.println(Timestamp.valueOf(sb.toString()));
		
//		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
//		try {
//			Date data = sdf.parse("19690827");
//			System.out.println(data);
//			Timestamp.
//		} catch (ParseException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		System.out.println(Timestamp.valueOf("2011-05-09 11:49:45"));
//		System.out.println(Timestamp.valueOf("1969-08-27 00:00:00"));
//		System.out.println(Timestamp.valueOf("1969-08-27"));
	}
	
	public void m3() {
		Date now = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
		
//		String time = "05:12:23";//-10057000
//		String time = "07:00:00";//-3600000
//		String time = "07:12:23";//-2857000
//		String time = "07:32:23";//-1657000
//		String time = "07:52:23";//-457000
//		String time = "08:00:00";// 0
//		String time = "08:12:23";// 743000
		String time = "16:48:04";// 31684000
//		[07:12:23, 11:30:00]
		try {
			long timeL = sdf.parse(time).getTime();
			System.out.println("timeL =" + timeL);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
		String nowStr = sdf.format(now);
		System.out.println("nowStr ="+nowStr);
		try {
			System.out.println("nowL=" + sdf.parse(nowStr).getTime());
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
	}

	public void m4() {
		Date now = new Date();
		String sts = "14:00";
		String ets = "18:00";

		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
		try {
			Date st = sdf.parse(sts);
			Date et = sdf.parse(ets);

			String nowStr = sdf.format(now);
			Date nowTime = sdf.parse(nowStr);

			if (st.before(nowTime)) {
				System.out.println("--1----");
			}
			if (et.after(nowTime)) {
				System.out.println("--2----");
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}

	}


	public int getEntStatus(Boolean enabled, Integer vacation, String workTime) {
		if (!enabled) {
			return 3;
		}

		if (vacation == 1) {
			return 2;
		}

		if (StringUtils.isNullOrEmpty(workTime)) {
			return 1;
		}

		String[] workTimeArr = workTime.split("-");
		if (workTimeArr.length != 2) {
			return 1;
		}

		Date now = new Date();

		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
		try {
			String nowStr = sdf.format(now);
			Date nowTime = sdf.parse(nowStr);

			Date st = sdf.parse(workTimeArr[0]);
			Date et = sdf.parse(workTimeArr[1]);

			if (nowTime.before(st) || nowTime.after(et)) {
				return 1;
			}

		} catch (ParseException e) {
			e.printStackTrace();
			return 1;
		}

		return 0;
	}

	public void testSdf() {
		SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMddHHmmssSSS");
		Date now = new Date();
		System.out.println(sdf2.format(now));

	}

	public void testDate() {
		DateTime sDay = DateUtil.offsetDay(new Date(), -3);
		System.out.println(sDay.toString("yyyy-MM-dd HH:mm:ss"));

	}

	public void m5() {
		System.out.println(DateUtil.offsetMinute(new Date(), 10).toString("yyyy-MM-dd HH:mm:ss"));
	}

	public void m6() {
		String expiretime = "2022-04-26 17:21:00";
		int comp = DateUtil.parse(expiretime, "yyyy-MM-dd HH:mm:ss").compareTo(new Date());
		long times = DateUtil.parse(expiretime, "yyyy-MM-dd HH:mm:ss").between(new Date(), DateUnit.SECOND);
		System.out.println(comp + "---" + times);
	}
	
	
	public static void main(String[] args) {
		TimeTest tt = new TimeTest();
//		tt.m1();
//		tt.m2();
//		tt.m3();
//		tt.m4();
//		tt.m5();
		tt.m6();
//		System.out.println(tt.getEntStatus(false, 1, "14:00-19:00"));
//		System.out.println(tt.getEntStatus(true, 0, "16:00-19:00"));
//		tt.testSdf();//20210823 16 46 07 920
//		tt.testDate();
	}
}
